package com.mc.code.web.sys;

import com.mc.code.entity.sys.SysUser;
import com.mc.code.sysService.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.xml.ws.Action;

@Controller
public class Test {
    @Autowired
    private SysUserService sysUserService;
    @RequestMapping("/test")
    public String addAdmin(HttpServletRequest request, Model model){
        String adminNo = request.getParameter("adminNo");
        String adminName = request.getParameter("adminName");
        String password = request.getParameter("password");
        String state = "1";
        //将数据封装到系统管理员对象中
        SysUser sysUser = new SysUser("adminNo","adminName","password",null,"state");
        //将数据添加到数据库中
        sysUserService.save(sysUser);
        //根据新加的管理员查询id
        int sysUserId = sysUserService.findIdByAdminNo(adminNo);
        int sysRoleId = Integer.parseInt(request.getParameter("right"));
        //向sys_user_role表中插入数据
//        sysUserService.saveToUserRole(sysUserId,sysRoleId);
        //重定向到管理员列表
        return "redirect:/adminManage";
    }

}
